#ifndef SOCKET_H_
#define SOCKET_H_

#include "base/base.h"

namespace unet {
class Socket {
 public:
  Socket(int32 doman, int type, int protocol)
      : sock_(INVALIED_FD),
        doman_(doman),
        type_(type),
        protocol_(protocol) {
  }
  virtual ~Socket() {
    if (sock_ != INVALIED_FD) {
      ::close(sock_);
    }
  }

  int32 Fd() const {
    return sock_;
  }

  bool Open();
  void SetNonBlock();
  void SetBlock();

 protected:
  int32 sock_;

 private:
  int32 doman_;
  int32 type_;
  int32 protocol_;

  void OperateFlag(bool is_set, uint32 flag);

  DISALLOW_COPY_AND_ASSIGN(Socket);
};
}

#endif /* SOCKET_H_ */
